package task.www.lagou.app;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import task.www.lagou.entity.Phone;
import task.www.lagou.utils.DruidUtils;

import java.sql.SQLException;
import java.util.List;

/**
 * 2) 需求1:  查询价格高于2000元，生产日期是2019年之前的所有手机
 *
 * 3) 需求2:  查询所有颜色是白色的手机信息
 */
public class TestQuestion2 {
    public static void main(String[] args) {
        QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());

        try {
            String sql1 ="SELECT * FROM phone WHERE price > 2000 AND prodate < '2019-01-01'";
            List<Phone> list = qr.query(sql1,new BeanListHandler<Phone>(Phone.class));

            System.out.println("查询价格高于2000元，生产日期是2019年之前的所有手机");
            for(Phone p : list){
                System.out.println(p);
            }

            String sql2 ="SELECT * FROM phone WHERE color ='白色'";
            List<Phone> list1 = qr.query(sql2,new BeanListHandler<Phone>(Phone.class));

            System.out.println("查询所有颜色是白色的手机信息");
            for(Phone p : list1){
                System.out.println(p);
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }


}
